<template>
  <div class="header-container">
    <div class="top-header">
      <el-dropdown trigger="click" @command="handleCommand">
        <span class="el-dropdown-link">
          {{userName}}<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="modifyPwd">修改密码</el-dropdown-item>
          <el-dropdown-item command="modifyInfo">修改资料</el-dropdown-item>
          <el-dropdown-item command="logout" divided>退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
    <div class="breadcrumb">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item v-for="(item, index) in $route.meta" v-bind:key="index">{{item}}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
  </div>
</template>

<script>
  import {getStore, removeStore} from '../config/mUtils'

  export default {
    name: "headTop",
    data() {
      return {
        userName: getStore('userName')
      }
    },
    created() {
      if (!getStore("userName")) {
        setTimeout(() => {
          this.$router.push('/signIn');
        }, 200);
      }
    },
    methods: {
      handleCommand(command) {
        if (command == 'logout') {
          this.logout();
        }
      },
      modifyPwd() {},
      modifyInfo() {},
      logout() {
        this.$message({
          message: '退出成功',
          type: 'success'
        });
        removeStore('userName');
        setTimeout(() => {
          this.$router.push('/signIn');
        }, 800);
      }
    }
  }
</script>
